home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
win
/
c
/
cdk_vb.exe
/
CDK_BC.TXT
< prev
Wrap
Text File
|
1991-09-01
|
25KB
|
627 lines
Using Borland C++ IDE with
the Microsoft Visual BASIC Control Development Kit (CDK)
I wrote this description to help anyone using Borland's C++
compiler and Integrated Development Environment (IDE) to create
custom controls for use with Microsoft's Visual BASIC. The MS
CDK (Control Development Kit) has a series of example programs
that were written to work with Microsoft C version 6 or later.
This document should help you get them to work using Borland's
development products.
This document assumes that you have purchased the MS CDK product.
I make reference to specific line numbers within the files that
were shipped to me with version 1.0 of that product. When
working with Borland's IDE, you can tell what line that you are
currently editing by referencing the numbers in the bottom left-
hand corner of the active edit window. The numbers shown there
appear in the format:
<line number> : <column position>
for example:
25:32
which says that your cursor is on the 32nd character of line 25.
In this document, I also assume that you have installed your
Borland C++ product in the drive\subdirectory C:\BORLANDC. Also
that after installing the CDK, you have copied the file VBAPI.LIB
to C:\BORLANDC\LIB and the file VBAPI.H to C:\BORLANDC\INCLUDE.
While experimenting with this code, I created a subdirectory
called TEMP under the directory for each control, copied all
files for that control there, and edited the copies. It is NEVER
advisable to edit your original copies of anything. Also
remember that whenever you are coding at a systems-level, you
should save your code frequently.
If you have any comments, suggestions, or neat VBX files, please
feel free to drop me a line in my Compuserve mailbox, or at my
humble homestead at 1188 Morgan Ave, Williamsport, PA 17701.
Throughout this document, I mention products and programs that
are protected by some sort of legal nonsense or another, and I
hope I can appease all legal-eagles by saying that any Borland
product mentioned is trademarked and legally protected by Borland
International Inc. of Scotts Valley, CA. Any Microsoft product
is trademarked and legally protected by Microsoft Corporation of
Redmond, WA. Anything done by you using the descriptions here
should make neither them (nor me) liable for any silliness that
might prevail.
Brent K. Langley Compuserve Userid 70312,2142 Page 1
Using Borland C++ IDE with
the Microsoft Visual BASIC Control Development Kit (CDK)
GETTING THE CDK TO WORK:
I have found that in getting the CDK code to work with the IDE
there are 8 steps that I had to follow:
1) Change WINDOWS.H
2) Copy and Rename LibInit.Obj to C:\BORLANDC\LIB\C0VBINIT.OBJ
3) Create a Project file (.PRJ) to create the VBX/DLL file
4) Change CCINIT.C to take advantage of changes in WINDOWS.H
5) Handle any syntax errors in demo code
6) Handle any language incompatibilities in code
7) "Make" Project from IDE
8) Rename (or Copy) xxxxxxxx.DLL to xxxxxxxx.VBX
Steps 1 and 2 from above only need to be done once. Steps 3 and
4 need to be done for every project, but follow the same steps.
Steps 5 and 6 will be addressed separatly for each of the three
example programs that need fixing. Steps 7 and 8 let you put all
of the pieces together.
STEP ONE: CHANGE WINDOWS.H
The normal startup code for a DLL does a little processing and
then calls your function called LibMain. In a .VBX file, we have
to replace the normal startup code with a modified routine that
passes some extra information to our control's LibMain. This
means that the format for calling a VBX's LibMain is different
from a normal DLL's LibMain. This causes no real hassle to
MSC/SDK developers because Microsoft doesn't include a function
prototype in their version of WINDOWS.H for LibMain, however,
Borland does. And when Borland's compiler sees the CDK version
of the LibMain function, it stops compiling with an error.
We could just remove the function prototype for LibMain from
Borland's WINDOWS.H, but it will help us with our syntax checking
if we leave it there. My solution is to define a constant called
_CDK before the #include of WINDOWS.H. Then have WINDOWS.H
determine the existance of this defined constant to decide
whether to use the CDK or normal version of LibMain.
To do this, load C:\BORLANDC\INCLUDE\WINDOWS.H and then press
Ctrl-PgDn to go to the bottom of the file. Move your cursor up
to about line 3473, and you should see Borland's function
prototype for LibMain. I changed this part of the code to be:
#ifndef _CDK
int FAR PASCAL LibMain ( HANDLE, WORD, WORD, LPSTR );
#else
BOOL FAR PASCAL LibMain( HANDLE, HANDLE, unsigned short );
#endif
I used "unsigned short" instead of USHORT for the third parameter
of the CDK version of LibMain because USHORT isn't seen in a
typedef statement until the file VBAPI.H is #include'd later.
Brent K. Langley Compuserve Userid 70312,2142 Page 2
Using Borland C++ IDE with
the Microsoft Visual BASIC Control Development Kit (CDK)
STEP TWO: RENAME LIBINIT.OBJ TO C0VBINIT.OBJ
Page 20 of the CDK Guide explains that LIBINIT.OBJ contains
initialization code to replace the code from the file
LIBENTRY.OBJ that is normally linked into DLL projects first. So
we must ensure that the code from LIBINIT.OBJ is linked before
any other code in our projects.
On page 141 of Borland's C++ User Guide, we find the section of
the project manager chapter titled "Overriding Libraries" states
that we can have our own startup file linked first, if:
1) its name starts with C0 (the letter C followed by zero)
2) it is placed as the first file in the project.
We'll worry about making a project file in a minute, but for now,
lets give LibInit.OBJ a new name to conform with step one from
above. While we're at it, lets also move it to a standard
location (since the CDK manual says that this code would seldom
need to change.) If LibInit.OBJ is in your current directory,
type:
COPY LIBINIT.OBJ C:\BORLANDC\LIB\C0VBINIT.OBJ
You could call it anything you want (so long as it starts with
"C0") but since it contains the Visual Basic INITialization code,
I thought that this name was appropriate.
STEP THREE: CREATE A PROJECT FILE
For each control, you will make a project file that looks similar
to the following:
C:\BORLANDC\LIB\C0VBINIT.OBJ
C:\BORLANDC\LIB\C0DC.OBJ
C:\BORLANDC\LIB\VBAPI.LIB
CCINIT.C
program.DEF
program.RC
program.C